// 工厂函数
function createObj(o) {
  function F() {}
  F.prototype = o.prototype;
  return new F();
}

function createObj1(o) {
  return Object.create(o.prototype);
}

function createObj2(o) {
  let obj = {};
  Object.setPrototypeOf(obj, o.prototype);
  return obj;
}

// 寄生式函数
function inherit(Subtype, SuperType) {
  Subtype.prototype = createObj(SuperType);

  Object.defineProperties(Subtype.prototype, 'constructor', {
    writable: true,
    enumerable: false,
    configurable: true,
    value: Subtype,
  });
}

function Person(name, age) {
  this.name = name;
  this.age = age;
}
Person.prototype.running = function () {
  console.log('running');
};

function Student(name, age, sno) {
  Person.call(this, name, age);
  this.sno = sno;
}
inherit(Student, Person);

/**
 * 2
 */

function co1(F) {
  return Object.create(F.prototype);
}

function co2(F) {
  function Fn() {}
  Fn.prototype = F.prototype;
  return new Fn();
}

function co3(F) {
  let obj = {};
  Object.setPrototypeOf(obj, F.prototype);
  return obj;
}

function inherit(Subtype, SuperType) {
  Subtype.prototype = co1(SuperType);

  Object.defineProperty(Subtype.prototype, 'constructor', {
    writable: true,
    enumerable: false,
    configurable: true,
    value: Subtype,
  });
}

function Person(name, age) {
  this.name = name;
  this.age = age;
}

Person.prototype.running = function () {
  console.log('running!!');
};

function Student(name, age, sno) {
  Person.call(this, name, age);
  this.sno = sno;
}

inherit(Student, Person);

/**
 * 3
 */
function createObject1(F) {
  return Object.create(F.prototype);
}

function createObject2(F) {
  let obj = {};
  obj.setPrototypeOf(F.prototype);
  return obj;
}

function createObject3(F) {
  function Fn() {}
  Fn.prototype = F.prototype;
  return new Fn();
}

function inherit(Subtype, SuperType) {
  Subtype.prototype = createObj1(SuperType);
  Object.defineProperty(Subtype.prototype, 'constructor', {
    writable: true,
    enumerable: false,
    configurable: true,
    value: Subtype,
  });
}

function Person(name, age) {
  this.name = name;
  this.age = age;
}
Person.prototype.running = () => {
  console.log('running');
};

function Student(name, age, seo) {
  Person.call(this, name, age);
  this.seo = seo;
}
inherit(Student, Person);

/**
 * 4
 */
function createObj(F) {
  return Object.create(F.prototype);
}

function createObj(F) {
  let obj = {};
  Object.setPrototypeOf(obj, F.prototype);
  return obj;
}

function createObj(F) {
  function Fn() {}
  Fn.prototype = F.prototype;
  return new Fn();
}

function inherit(SubType, SuperType) {
  SubType.prototype = inherit(SuperType);

  Object.defineProperty(SubType.prototype, 'constructor', {
    writable: true,
    enumerable: false,
    configurable: true,
    value: SubType,
  });
}

function Person(name, age) {
  this.name = name;
  this.age = age;
}

function Student(name, age, sex) {
  Person.call(this, name, age);
  this.sex = sex;
}

inherit(Student, Person);
